#!/usr/bin/python
#coding:utf-8 
import json
import os,sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  
sys.path.append(BASE_DIR)  # 如果 没有这两句话, vscode 导包找不到 ,太tm狗了
# 导入 我们写好的 filepatth 类
from Commons.filePath import FilePath
bgpath =FilePath("static/bgimg")
formatimg =FilePath("static/formatimg")
commonimg =FilePath("static/common")
f =FilePath("Config/config.json")
class Config():
    def __init__(self):
        self.configpath=f.path() 
        self.bgpath=bgpath.path()
        self.formatimg=formatimg.path()
        self.commonimg=commonimg.path()
    def read_config(self):
        """"读取配置"""
        with open(self.configpath,"r",encoding='utf-8') as json_file:
            config = json.load(json_file)
        return config

    def imgConfig(self):
        """ 专门返回 
          图片的配置
          返回格式 :{'width': 260, 'height': 160}
        """
        imgconfg=self.read_config()
        return imgconfg["imgConfig"]

    def masklist(self):
        """
         缺口图 动态挑选
         返回数组  [0,1,2]
        """
        maskList=self.read_config()
        return maskList["masklist"]
    def bglist(self):
        imagelist = []
        for parent, dirnames, filenames in os.walk(self.bgpath):
            for filename in filenames:
                if filename.lower().endswith(( '.png', '.jpg', '.jpeg')):
                    imagelist.append(os.path.join(parent, filename))
        return imagelist 
    def formatlist(self):
        imagelist = []
        for parent, dirnames, filenames in os.walk(self.formatimg):
            for filename in filenames:
                if filename.lower().endswith(( '.png', '.jpg', '.jpeg')):
                    imagelist.append(os.path.join(parent, filename))
        return imagelist 


    def commontlist(self):
        
        imagelist = []
        for parent, dirnames, filenames in os.walk(self.commonimg):
            for filename in filenames:
                if filename.lower().endswith(( '.png', '.jpg', '.jpeg')):
                    imagelist.append(os.path.join(parent, filename))
        return imagelist 

    def appSetting(self): 
        appsetting=self.read_config()
        return appsetting["appSetting"]

# Todo 测试 是否 符合要求
# if __name__=="__main__":
#     sde=Config()
#     sddd=sde.bglist()
#     print(sddd)